<template>
	<view class="center">
		<view class="logo" @click="goLogin" :hover-class="!login ? 'logo-hover' : ''">
			<image class="logo-img" 
			:src="login ? uerInfo.avatar :avatarUrl"></image>
			<view class="logo-title">
				<text class="uer-name">{{login ? uerInfo.username : '您未登录'}}</text>
				<text class="go-login navigat-arrow" v-if="!login">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<navigator url="/pages/list/sale_list" class="center-list-item">
				<text class="list-icon">&#xe60c;</text>
				<text class="list-text">我的寄售</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</navigator>
			<navigator url="/pages/order/order" class="center-list-item">
				<text class="list-icon">&#xe60d;</text>
				<text class="list-text">我的订单</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</navigator>
			<navigator url="/pages/user/address" class="center-list-item">
				<text class="list-icon">&#xe60d;</text>
				<text class="list-text">收货地址</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</navigator>
			<navigator url="/pages/list/star_list" class="center-list-item">
				<text class="list-icon">&#xe60d;</text>
				<text class="list-text">我的收藏</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</navigator>
		</view>
		<view class="center-list">
			<view class="center-list-item border-bottom"  @click="toUserOpt" >
				<text class="list-icon">&#xe60b;</text>
				<text class="list-text">账号管理</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view v-show="login" class="center-list-item" @click="logout" >
				<text class="list-icon">&#xe61a;</text>
				<text class="list-text">退出登录</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
	</view>
</template>

<script>
	import { getItem,removeItem } from "@/utils/selfLocalStorage.js"
	
	export default {
		data() {
			return {
				login: false,
				avatarUrl: '/static/logo.png',
				uerInfo: {
					avatar:null,
					username:null
				}
			}
		},
		onLoad() {
			
		},
		onShow() {
			// 获取用户数据
			this.uerInfo.avatar = getItem("avatar");
			this.uerInfo.username = getItem("username");
			if( getItem("uid")){
				this.login = true;
			}else{
				this.login = false;
			}
		},
		methods: {
			goLogin() {
				if (!this.login) {
					uni.navigateTo({
						url: '/pages/login/login'
					});
				}
			},
			goAbout() {
				uni.navigateTo({
					url: '/pages/about/about'
				});
			},
			
			// 用户设置
			toUserOpt(){
				uni.navigateTo({
					url:"/pages/user/user-option/user-option"
				})
			},
			
			
			// 退出登录
			logout(){
				// 删除数据
				removeItem("token");
				removeItem("uid");
				removeItem("username");
				
				// 返回登录
				uni.navigateTo({
					url:"/pages/login/login"
				})
			}
		}
	}
</script>

<style>
</style>
